package thu.cs.segroup.util;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

public class Utility {

	public static String getLocalIPAddress() {
		Enumeration<NetworkInterface> netInterfaces = null;   
		try {   
			netInterfaces = NetworkInterface.getNetworkInterfaces();   
			while (netInterfaces.hasMoreElements()) {   
				NetworkInterface ni = netInterfaces.nextElement();   
				// System.out.println("DisplayName:" + ni.getDisplayName());   
				// System.out.println("Name:" + ni.getName());   
				if (ni.getName().equalsIgnoreCase("eth0")) {
					Enumeration<InetAddress> ips = ni.getInetAddresses();
					while (ips.hasMoreElements()) {   
						// System.out.println("IP:"  
								// + ips.nextElement().getHostAddress());
						String ip = ips.nextElement().getHostAddress();
						if (ip.indexOf(".") != -1) {
							return ip;
						}
					}
				}	     
			}   
		} catch (Exception e) {   
			e.printStackTrace();   
		} 
		return null;
	}
	
	public static void main(String argv[]) {
		System.out.println(Utility.getLocalIPAddress());
	}
	
}
